package com.deluxelx.rmo.common.util;

import java.time.LocalDateTime;

/**
 * 处理时间类的一些工具类
 */
public class DateUtil {

    // 得到帖子每天的动态时间
    public static String getPostTime(LocalDateTime dateTime) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime yesterday = now.minusDays(1);
        LocalDateTime twoDaysAgo = now.minusDays(2);

        String postTime;
        if (now.toLocalDate().isEqual(dateTime.toLocalDate())) {
            postTime = "今天" + dateTime.getHour() + ":" + dateTime.getMinute();
        } else if (yesterday.toLocalDate().isEqual(dateTime.toLocalDate())) {
            postTime = "昨天" + dateTime.getHour() + ":" + dateTime.getMinute();
        } else if (twoDaysAgo.toLocalDate().isEqual(dateTime.toLocalDate())) {
            postTime = "前天" + dateTime.getHour() + ":" + dateTime.getMinute();
        } else {
            postTime = dateTime.getMonthValue() + "月" + dateTime.getDayOfMonth() + "日" + dateTime.getHour() + ":" + dateTime.getMinute();
        }
        return postTime;
    }

}
